/**
 * Created by LENOVO on 2016/8/29.
 * 用于从receiveWork.jsp转到controller里处理并跳转到workDetail.jsp
 */
var contextPath = "/";
$(function () {
    contextPath += window.location.pathname.split("/")[1];
    $("#toptitle").html("作业任务表");
    $.ajaxSetup({
        async:false
    });
        var url = contextPath+"/teacherWorkController/getall.wm";
        data = {};
        $.post(url,data,function (result) {
            var newrow = "";
            for(var i=0;i<result.all.length;i++){
                var jobTaskId = result.all[i].aJobTask.jobTask_id;
                var classname = result.all[i].aClass.class_name;
                var ss  = result.all[i].aJobTask.jobTask_reportTime.split(" ");
                var reportTime = ss[0];
                var title = result.all[i].aJobTask.jobTask_title;
                var num = result.totalNum[jobTaskId];
                newrow += "<tr class='tlength'><td>"+classname+"</td><td>"+reportTime+"</td><td>"+title+"</td><td>"+num+"</td>"+
                    "<td><a  href='"+contextPath+"/teacherWorkController/workDetail.wm?id="+jobTaskId+"'>点我查看</a></td></tr>"
            }
            $("#datas tbody").html(newrow);
            $("#total").text($(".tlength").length);
        },"json");
    //实现搜索功能
    $(".serachbtn").click(function () {
        var text = $(".serachText").val();
        var url = contextPath+"/teacherWorkController/search.wm";
        data = {};
        data.text = text;
        $.post(url,data,function (result) {
            var newrow = "";
            for(var i=0;i<result.all.length;i++){
                var jobTaskId = result.all[i].aJobTask.jobTask_id;
                var classname = result.all[i].aClass.class_name;
                var ss  = result.all[i].aJobTask.jobTask_reportTime.split(" ");
                var reportTime = ss[0];
                var title = result.all[i].aJobTask.jobTask_title;
                var num = result.totalNum[jobTaskId];
                newrow += "<tr class='tlength'><td>"+classname+"</td><td>"+reportTime+"</td><td>"+title+"</td><td>"+num+"</td>"+
                    "<td><a  href='"+contextPath+"/teacherWorkController/workDetail.wm?id="+jobTaskId+"'>点我查看</a></td></tr>"
            }
            $("#datas tbody").html(newrow);
            $("#total").text($(".tlength").length);
        },"json");
    });
    
    $("#table_demo3 .holder").jPages({
        containerID : "data",
        previous : "«",
        next : "»",
        perPage : 6,
        delay : 10,
        callback: function(pages, items){
            $('#total').text(items.count);
            $('#cur_page').text(pages.current);
            $('#total_page').text(pages.count);
        }
    });
  
});

